package com.tengfei.api.user;

import com.tengfei.common.annotation.Anonymous;
import com.tengfei.common.core.controller.BaseController;
import com.tengfei.common.core.domain.PageQuery;
import com.tengfei.common.core.domain.R;
import com.tengfei.common.core.page.TableDataInfo;
import com.tengfei.main.user.domain.SearchEntity;
import com.tengfei.main.user.domain.bo.course.CourseProgressBo;
import com.tengfei.main.user.domain.vo.course.*;
import com.tengfei.main.user.service.IUserPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author feige
 * @version v1.0
 * @date 2022-08-09-17:02
 * @description 用户课程
 */

@RestController
@RequestMapping("/user/plan")
@Validated
@Api(value = "用户学习计划控制器", tags = {"用户学习计划模块"})
public class UserPlanController extends BaseController {

    @Resource
    private IUserPlanService userCourseService;

    /**
     * 用户学习计划列表
     *
     * @return
     */
    @ApiOperation("查询用户学习计划列表")
    @GetMapping("/list")
    public R<List<UserPlanVo>> planList() {
        return R.ok(userCourseService.planList());
    }


    /**
     * 查询用户学习计划下课程列表
     *
     * @param planId
     * @return
     */
    @ApiOperation("查询用户课程列表(学习计划下)")
    @GetMapping("/course/list")
    public R<List<UserCourseVo>> courseListByPlanId(@ApiParam("学习计划id") @RequestParam("planId") Long planId) {
        return R.ok(userCourseService.courseList(planId));

    }

    /**
     * 用户某个课程下的章节列表
     *
     * @param courseId
     * @return
     */
    @ApiOperation("查询课程下章节列表")
    @GetMapping("/chapter/list")
    public R<List<UserChapterVo>> chapterListByCourseId(@ApiParam("课程id") @RequestParam("courseId") Long courseId) {
        return userCourseService.chapterList(courseId);
    }

    /**
     * 查询视频详细信息
     *
     * @param chapterId
     * @return
     */
    @ApiOperation("查询视频详细信息")
    @GetMapping("/video")
    public R<UserVideoVo> videoByVideoId(@ApiParam("课程id") @RequestParam("courseId") Long courseId,
                                         @ApiParam("章节id") @RequestParam("chapterId") Long chapterId,
                                         @ApiParam("视频id") @RequestParam("videoId") Long videoId) {
        return R.ok(userCourseService.videoByVideoId(courseId, chapterId, videoId));
    }

    /**
     * 查询课程观看历史记录
     *
     * @return
     */
    @ApiOperation("查询课程观看历史记录")
    @GetMapping("/course/history")
    public R<List<CourseHistoryVo>> courseViewHistory(@ApiParam("列表大小(默认为6)")
                                                      @RequestParam(value = "size", defaultValue = "6") Integer size) {
        return R.ok(userCourseService.courseViewHistory(size));
    }

    @ApiOperation("查询课程观看历史记录根据课程id")
    @GetMapping("/course/history/{courseId}")
    public R<CourseHistoryVo> courseViewHistoryById(@PathVariable("courseId") Long courseId) {
        return userCourseService.courseViewHistoryById(courseId);
    }

    /**
     * 上传观看进度
     *
     * @return
     */
    @ApiOperation("上传观看进度")
    @PostMapping("/course/progress")
    public R<Void> courseViewProgress(@RequestBody CourseProgressBo progressBo) {
        return toAjax(userCourseService.uploadProgress(progressBo));
    }

    /**
     * 查询课程下附件列表(按课程划分)
     *
     * @return
     */
    @ApiOperation("查询课程下附件列表")
    @GetMapping("/course/res")
    public R<List<UserResVo>> courseViewHistory(@ApiParam("课程id") @NotNull(message = "课程id不能为空")
                                                @RequestParam("courseId") Long courseId,
                                                @ApiParam("文件类型") @RequestParam(value = "resType", required = false)
                                                        Integer resType) {
        return R.ok(userCourseService.courseResList(courseId, resType));
    }

    /**
     * 查询公开课程列表
     *
     * @param search
     * @param pageQuery
     * @return
     */
    @Anonymous
    @GetMapping("/pubCourse/list")
    @ApiOperation("查询公开课程列表")
    public R<TableDataInfo<UserCourseVo>> courseList(SearchEntity search, PageQuery pageQuery) {
        return R.ok(userCourseService.pubCourseList(search, pageQuery));
    }

    /**
     * 查询附件资源列表详细信息
     *
     * @param resIds
     * @return
     */
    @ApiOperation("查询附件资源列表详细信息")
    @GetMapping("/res")
    public R<List<UserResVo>> resByResId(@ApiParam("附件id列表") @NotNull(message = "附件id列表不能为空")
                                         @RequestParam("resIds") List<Long> resIds) {
        return R.ok(userCourseService.resListByIds(resIds));
    }


}
